﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;


namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OQualityStrategyListEasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OQualityStrategyListEasyUI";
            }
        }

        #region 属性 (查询条件)

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "QSID" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }


        protected string DuiCuBianHao
        {
            get
            {
                return GetRequestValue<string>("DuiCuBianHao", "");

            }
        }
        protected string ItemCode
        {
            get
            {
                return GetRequestValue<string>("ItemCode", "");

            }
        }
        protected string MacType
        {
            get
            {
                return GetRequestValue<string>("MacType", "");

            }
        }
        protected string ProblemClass
        {
            get
            {
                return GetRequestValue<string>("ProblemClass", "");

            }
        }

        protected string Frequency
        {
            get
            {
                return GetRequestValue<string>("Frequency", "");
            }
        }
        protected string DownlineDateFrom
        {
            get
            {
                return GetRequestValue<string>("DownlineDateFrom", "");

            }
        }
        protected string DownlineDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(DownlineDateFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("DownlineDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(DownlineDateFrom).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
                    else
                        return todate;
                }

            }
        }


        protected string commfieldsname
        {
            get
            {
                return GetRequestValue<string>("commfieldsname", "");
            }
        }
        protected string commfieldsvalue
        {
            get
            {
                return GetRequestValue<string>("commfieldsvalue", "");
            }
        }
        #endregion
        protected string GetWhereSql()
        {
            string wheresql = " 1=1 ";
            if (!string.IsNullOrEmpty(ItemCode))
            {
                wheresql = string.Format(" (itemcode like '%{0}%' or itemname like '%{0}%') ", ItemCode);
            }

            if (!string.IsNullOrEmpty(DuiCuBianHao))
            {
                if (!string.IsNullOrEmpty(wheresql))
                    wheresql += string.Format(" and DuiCuBianHao like '%{0}%'", DuiCuBianHao);
                else
                    wheresql = string.Format(" DuiCuBianHao like '%{0}%'", DuiCuBianHao);
            }

            if (!string.IsNullOrEmpty(ProblemClass))
            {
                if (!string.IsNullOrEmpty(wheresql))
                    wheresql += string.Format(" and ProblemClass like'%{0}%'", ProblemClass);
                else
                    wheresql = string.Format(" ProblemClass l ike'%{0}%'", ProblemClass);
            }

            if (!string.IsNullOrEmpty(Frequency))
            {
                if (!string.IsNullOrEmpty(wheresql))
                    wheresql += string.Format(" and Frequency like '%{0}%'", Frequency);
                else
                    wheresql = string.Format(" Frequency like '%{0}%'", Frequency);
            }

            //string DOWNSQL = "";
            //if (!string.IsNullOrEmpty(DownlineDateFrom))
            //{
            //    DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("IssueDate", QueryOperatorsEnum.范围, DownlineDateFrom + "|" + DownlineDateTo);
            //    if (!string.IsNullOrEmpty(wheresql))
            //    {
            //        wheresql += " and " + DOWNSQL;
            //    }
            //    else
            //    {
            //        wheresql = DOWNSQL;
            //    }
            //}



            return wheresql;
        }


        protected override string query()
        {
            DataTable dts = OQualityStrategyController.GetPagination(GetWhereSql(), pageNum, numPerPage, SQLSort, ref TotalCount);

            return ToDataGridJson(dts, TotalCount, null).ToString();
        }
    }
}